package com.zlq.cn.controller.sign.fanyi;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.annotations.UnSigned;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.bootstrap.SignApiBootstrap;
import com.zlq.cn.config.Config;
import com.zlq.cn.dto.param.FanyiFeedbackParam;
import com.zlq.cn.dto.param.VipUpParam;
import com.zlq.cn.entity.FanyiUser;
import com.zlq.cn.entity.SuggestRecord;
import com.zlq.cn.service.un.FanyiUserService;
import com.zlq.cn.service.un.SuggestRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhoucl
 * @since 2022-03-05
 */
@Api(tags = "翻译-用户")
@Validated
@RestController
@RequestMapping("/fanyi/user")
public class FanyiUserController {

    @Resource
    private FanyiUserService fanyiUserService;

    @Resource
    private SuggestRecordService suggestRecordService;

    @ApiOperation("获取服务器时间")
    @GetMapping("/sys/time")
    public SignApiResult<Long> sysTime() {
        return SignApiResult.resultSuccess(System.currentTimeMillis());
    }

    @UnSigned
    @ApiOperation("ios内购回调")
    @PostMapping("/ios/callback")
    public SignApiResult<String> iosCallback(@RequestBody JSONObject param) {
        fanyiUserService.iosCallback(param);
        return SignApiResult.resultSuccess("内购成功");
    }

    @ApiOperation("微软文本翻译")
    @PostMapping("/microsoft/text/translate")
    public SignApiResult<String> microsoftTextTranslate(@RequestBody JSONObject param) {
        return SignApiResult.resultSuccess(fanyiUserService.microsoftTextTranslate(param));
    }

    @ApiOperation("支付成功单号上报")
    @PostMapping("/ios/order/up")
    public SignApiResult<String> iosOrderUp(@RequestBody JSONObject param) {
        fanyiUserService.iosOrderUp(param);
        return SignApiResult.resultSuccess("支付单号上报成功");
    }

    @ApiOperation("公共用户登录/注册")
    @PostMapping("/common/login")
    public SignApiResult<FanyiUser> commonLogin(@RequestBody Object o) {
        return SignApiResult.resultSuccess(fanyiUserService.commonLogin());
    }

    @ApiOperation("用户登录/注册")
    @PostMapping("/login")
    public SignApiResult<FanyiUser> login(@RequestBody Object o) {
        return SignApiResult.resultSuccess(fanyiUserService.login(Config.PROJECT_FANYI));
    }

    @ApiOperation("用户VIP上报")
    @PostMapping("/vip/up")
    public SignApiResult<Object> vipUp(@Valid @RequestBody VipUpParam vipUpParam) {
        return SignApiResult.resultSuccess(fanyiUserService.vipUp(vipUpParam));
    }

    @ApiOperation("VIP永久")
    @PostMapping("/vip/permanent")
    public SignApiResult<Object> vipPermanent(@RequestBody Object o) {
        return SignApiResult.resultSuccess(fanyiUserService.vipPermanent());
    }

    @ApiOperation("用户反馈")
    @PostMapping("/feedback")
    public SignApiResult<Object> feedback(@RequestBody FanyiFeedbackParam fanyiFeedbackParam) {
        return SignApiResult.resultSuccess(fanyiUserService.feedback(fanyiFeedbackParam));
    }

    @ApiOperation("用户反馈列表")
    @PostMapping("/feedback/list")
    public SignApiResult<Page<SuggestRecord>> feedbackList(@RequestBody Page<SuggestRecord> page) {
        return SignApiResult.resultSuccess(suggestRecordService.lambdaQuery().page(page));
    }

    @ApiOperation("用户当前用户信息")
    @PostMapping("/getUserInfo")
    public SignApiResult<Object> getUserInfo(@RequestBody Object o) {
        return SignApiResult.resultSuccess(SignApiBootstrap.requestFanYiUser());
    }
}

